from collections import OrderedDict

from django.shortcuts import render

# Create your views here.
from django.views import View

from apps.contents.utils import get_categories
from apps.goods.models import GoodsChannel
from apps.contents.models import ContentCategory

class IndexView(View):

    def get(self,request):
        #1查询商品频道和分类
        categories = get_categories()

        #2.广告楼层数据
        contents = {}
        # 2.1先查询分类信息
        contents_categories = ContentCategory.objects.all()

        # 2.2遍历
        for cat in contents_categories:
            contents[cat.key]=cat.content_set.filter(status=True).order_by('sequence')

        # 渲染模板的上下文
        context = {
            'categories': categories,
            'contents': contents

        }

        return render(request,'index.html',context)
